package com.qf.spring01.utils;

import com.qf.spring01.service.FangDong;

import java.lang.reflect.InvocationHandler;
import java.lang.reflect.Method;
import java.lang.reflect.Proxy;

public class MyProxyFactory {


    public static Object getProxy(Object target){
        ClassLoader classLoader = target.getClass().getClassLoader();
        Class<?>[] interfaces = target.getClass().getInterfaces();
        InvocationHandler h = new InvocationHandler() {
            @Override
            public Object invoke(Object proxy, Method method, Object[] args) throws Throwable {
                long start = System.currentTimeMillis();

                Object invoke = method.invoke(target, args);

                long end = System.currentTimeMillis();
                System.out.println("消耗时间："+(end-start));

                return invoke;
            }
        };

        Object o = Proxy.newProxyInstance(classLoader, interfaces, h);
        return o;
    }
}
